package com.sparrow.manage.template.data;

import com.sparrow.manage.template.data.strategy.IDataFetch;
import org.thymeleaf.context.IWebContext;
import org.thymeleaf.context.WebContext;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

/**
 * 模板数据收集策略上下文
 */
public class ThymeleafDataContext {

    public ThymeleafDataContext(IDataFetch dataFetch, HttpServletRequest request, HttpServletResponse response) {
        this.dataFetch = dataFetch;
        this.response = response;
        this.request = request;
    }

    private IDataFetch dataFetch;

    private HttpServletResponse response;

    private HttpServletRequest request;

    public IWebContext generateTemplateContext(){
        WebContext webContext = new WebContext(request, response, request.getServletContext());
        webContext.setVariables(dataFetch.getVariables());
        return  webContext;
    }

}
